
//走势图初始化  
function initDataTrendChart(point_num, time_interval) {
	Highcharts.setOptions({
		global : {
			useUTC : false
		}
	});
	// Create the chart
	window.chart = new Highcharts.Chart({
		chart : {
			renderTo : 'main_content', //要显示线状图的div的id
			type : 'line', //图表类型为线性图
			margin : 75,
		},
		title : {
			text : '这是一个测试的Demo'
		},
		subtitle : {
			text : 'Source: www.aaa.com'
		},
		credits: {  //版权信息
			enabled: true,
			href: 'http://www.baidu.com',
			text: 'HS.com'
        },
		xAxis : {
			type : 'datetime',
			dateTimeLabelFormats : {
				day : '%H:%M'
			}
		},
		yAxis : {
			title : {
				text : ''
			}
		},
		plotOptions : {
			line : {
				dataLabels : {
					enabled : true
				},
				enableMouseTracking : false
			}
		},
		series : [ {
			name : '进程数量',
			data : (function() {
				// generate an array of random data
				var data = [], time = (new Date()).getTime(), i;
				for (i = -point_num; i <= -1; i++) {
					data.push([ time + i * time_interval * 1000, 0 ]);
				}
				return data;
			})()
		}, {
			name : '剩余交互分区',
			visible : false, //初始化图片隐藏
			data : (function() {
				// generate an array of random data
				var data = [], time = (new Date()).getTime(), i;
				for (i = -point_num; i <= -1; i++) {
					data.push([ time + i * time_interval * 1000, 0 ]);
				}
				return data;
			})()
		}, {
			name : '运行时长',
			visible : false, //初始化图片隐藏
			data : (function() {
				// generate an array of random data
				var data = [], time = (new Date()).getTime(), i;
				for (i = -point_num; i <= -1; i++) {
					data.push([ time + i * time_interval * 1000, 0 ]);
				}
				return data;
			})()
		}, {
			name : '剩余内存',
			visible : false, //初始化图片隐藏
			data : (function() {
				// generate an array of random data
				var data = [], time = (new Date()).getTime(), i;
				for (i = -point_num; i <= -1; i++) {
					data.push([ time + i * time_interval * 1000, 0 ]);
				}
				return data;
			})()
		} ]
	});
}

//右侧页面加载
function loadRightPage(room_name, group) {
	$('#main_content').load(
			curPage,
			function() {
				initDataTrendChart(30, 5); //初始化图片  point_num 一张图多少个x坐标点  time_interval 多长时间添加一个点
				if (window.WebSocket) {
					if (window.socket_obj) {
						window.socket_obj.closeWebSocket();
					}
					window.socket_obj = new webSocketConnectInit({
						//reqUrl: ['ws://127.0.0.1:9696/websocket', [room_name + ' ' + group]]
						reqUrl : [ 'ws://123.56.67.133:9696/websocket', [ room_name + ' ' + group ] ]
					});
					window.socket_obj.init();
				}
			});
}

//刷新页面相关的数据
function refreshPageData(res) {
	res = eval('(' + res + ')');
	refreshChartTrend(res);
}

//刷新走势图数据  char类型导致 纵轴不支持小数 
function refreshChartTrend(res) {

	var x = res.clock
	if (res.key === "proc.num[]") {
		var y = parseInt(res.value);
		var procNum_series = window.chart.series[0]; //进程数量
		procNum_series.addPoint([ x, y ], true, true);
	}

	if (res.key === "system.swap.size[,free]") {
		var swapSize_series = window.chart.series[1]; //剩余交互分区
		swapSize_series.addPoint([ x, y ], true, true);
	}

	if (res.key === "system.uptime") {
		var upTime_series = window.chart.series[2]; //运行时长
		upTime_series.addPoint([ x, y ], true, true);
	}

	if (res.key === "vm.memory.size[free]") {
		var size = parseInt(res.value);
		var value = size / 1000 / 1000
		var memorySize_series = window.chart.series[3]; //剩余内存
		memorySize_series.addPoint([ x, Math.round(value) ], true, true);
	}

}
